package com.example.coupon.dao;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CouponMapper {

    @Insert("insert into coupon (activity_id, amount, type, status, start_time, end_time) values" +
            " (#{activityId}, #{amount}, #{type}, #{status}, #{startTime}, #{endTime})")
    Integer insertCoupon(@Param("activityId") Long activityId, @Param("amount") String amount,
                         @Param("type") Integer type, @Param("status") Integer status,
                         @Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("select * from coupon where status = #{status} and start_time <= NOW() and end_time > NOW()")
    List<Map<String, Object>> queryCanStartCoupon(@Param("status") Integer status);

    @Select("select * from coupon where status = #{status} and end_time < NOW()")
    List<Map<String, Object>> queryCanExpireCoupon(@Param("status") Integer status);

    @Update("update coupon set status=#{status} where id = #{id}")
    Integer updateStatusById(@Param("status") Integer status, @Param("id") Long id);

    @Select("select * from coupon where id = #{id}")
    Map<String, Object> queryCouponById(@Param("id") Long id);
}